package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import static java.lang.Integer.valueOf;

/**
 * CTassName: ShopOperation
 * Package: com.sky.controller.admin
 * Description:
 *
 * @Author xw
 * @Create 2023/11/20 18:28
 * @Version 1.0
 */
@RestController
@Api(tags = "店铺操作接口")
@Slf4j
public class ShopOperationController {

    @Autowired
    private RedisTemplate redisTemplate;

    public static final String KEY = "SHOP_STATUS";

    /**
     * 设置店铺的营业状态
     *
     * @param status
     * @return
     */
    @PutMapping("/admin/shop/{status}")
    @ApiOperation("设置店铺的营业状态")
    public Result setStatus(@PathVariable Integer status) {

        log.info("设置店铺的营业状态为：{}", status == 1 ? "营业中" : "打烊中");

        redisTemplate.opsForValue().set(KEY, status + "");


        return Result.success();
    }


    /**
     * 获取营业状态
     */
    @GetMapping("/admin/shop/status")
    @ApiOperation("获取营业状态")
    Result<Integer> BusinessStatus() {

        Object o = redisTemplate.opsForValue().get(KEY);
        log.info("---》 {} ", o);

        int i = Integer.parseInt(o + "");

        log.info("获取到店铺的营业状态为：{}",i== 1 ? "营业中" : "打烊中");


        return Result.success(i);
    }

}
